import React from 'react';

import {Route, Switch, withRouter} from 'react-router-dom';
import routes from './routeConfig';


function RouteComponent(props) {

    return (
        <div>
            <Switch>
                {
                    routes&&routes.length>0 ? routes.map((route, index) => {
                      return  <RouteWithSubRoutes key={index} {...route} />
                    })
                    : ''
                }
            </Switch>
        </div>
    )
}
const RouteWithSubRoutes = route => {
    return (

        <Route
            path={route.path}
            render={props => {
                return <route.component {...props} children={route.children} />
            }}
        />
    )
};

export default withRouter(RouteComponent)